package cn.zye.msa;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageView;

public class ImageDialog extends Dialog {
	Context context;
	String _src;
	private ImageView imgView;

	public ImageDialog(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
		this.context = context;
	}

	public ImageDialog(Context context, int theme, String src) {
		super(context, theme);
		this.context = context;
		_src = src;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.imgdialog);
		imgView = (ImageView) findViewById(R.id.imgView);
		
		BitmapFactory.Options o = new BitmapFactory.Options();
		o.inJustDecodeBounds = false;
		o.inSampleSize = 2;   
		try {
			imgView.setImageBitmap(BitmapFactory.decodeStream(new FileInputStream(_src), null, o));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		imgView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				if (event.getAction() == MotionEvent.ACTION_DOWN) {
					dismiss();
				}
				return false;
			}
		});
	}
}